package com.zenika.zenbinding.client.converter;

import com.zenika.zenbinding.client.exception.ConverterException;

/**
 * Converter for the Float class.
 * @author Zenika
 */
public class IntegerConverter implements Converter {

	public String fromObjectToString(Object object) throws ConverterException {
		try {
			Integer value = (Integer) object;
			return value.toString();
		} catch (ClassCastException e) {
			throw new ConverterException();
		}

	}

	public Object fromStringToObject(String string) throws ConverterException {
		try {
			Integer value = (string == null || string.length() == 0) ? null : new Integer(string);
			return value;
		} catch (NumberFormatException e) {
			throw new ConverterException();
		}
	}

}
